package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingprojectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目功能模块")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingprojectService nursingprojectService;

    /**
     * 分页查询护理项目
     * @param name
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping
    @ApiOperation("分页查询护理项目")
    public ResponseResult<PageResponse<NursingProjectVo>> queryPage(String name,Integer pageNum,Integer pageSize,Integer status){
        PageResponse<NursingProjectVo> response = nursingprojectService.queryPage(name,pageNum,pageSize,status);
        return success(response);
    }

    /**
     * 新增护理项目
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增护理项目")
    public ResponseResult addNursingProject(@RequestBody @ApiParam("新增护理项目信息") NursingProjectDto nursingProjectDto){
        nursingprojectService.addNursingProject(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询护理项目
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理项目")
    public ResponseResult<NursingProjectVo> getNursingProject(@PathVariable @ApiParam("查询id") Long id){
        NursingProjectVo nursingProjectVo = nursingprojectService.getNursingProject(id);
        return success(nursingProjectVo);
    }

    /**
     * 编辑护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation("编辑护理项目")
    public ResponseResult updateNursingProject(@RequestBody @ApiParam("编辑护理项目信息") NursingProjectDto nursingProjectDto){
        int rows = nursingprojectService.updateNursingProject(nursingProjectDto);
        return success(rows);
    }

    /**
     * 启用禁用功能
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启动禁用接口")
    public ResponseResult updateStatus(@PathVariable @ApiParam("启用项目id") Long id,@PathVariable @ApiParam("状态信息") Integer status){
        int rows = nursingprojectService.updatestatus(id,status);
        return toAjax(rows);
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除护理项目")
    public ResponseResult deleteNursingProject(@PathVariable @ApiParam("删除护理项目id") Long id){
        int rows = nursingprojectService.deteleNursingProject(id);
        return toAjax(rows);
    }
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult<List<NursingProjectVo>> getAll(){
        List<NursingProjectVo> nursingProjectVos = nursingprojectService.getall();
        return success(nursingProjectVos);
    }
}
